home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / info-service / gopher / Unix / GopherTools / gee.shar / gee < prev    next >
Encoding:
Text File  |  1993-07-11  |  17.4 KB  |  643 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # gee - gopher environment editor (Beta Test Version)
  4. # copyright (c) Bill Middleton, 1993 - all rights reserved
  5. # wjm@feenix.metronet.com
  6. #
  7. #      Absolutely No Warranty expressed or implied.  Use with care.
  8. #      Send comments, suggestions, and fixes to me please.
  9. #
  10. # Initial improvements suggested by Randy Bush, randy@psg.com
  11. # More help from moose@sunet.se, and jdc@selway.umt.edu.  
  12. # Many thanks to these and others who have sent commentary.
  13. # To get on the discussion list, drop me a line here at feenix. 
  14. #
  15.  
  16. require ("ctime.pl"); 
  17.  
  18. #  Configure Here for your site/preferences
  19.  
  20. $toplevel='/usr/pub/';            # make this your toplevel gopher dir
  21. $thishost='feenix.metronet.com';  # make this your host
  22. $plen = 19;                       # this page length works for 23-24 line terms
  23. $ed='/usr/bin/vi';                # or whatever
  24. $pager='/usr/local/bin/less';     # or whatever
  25. $mv='/bin/mv';                    # path to mv
  26. $cp='/bin/cp';                    # how we copy 
  27. $rm='/bin/rm -i';                 # safe rm
  28. $ln='/bin/ln ';                 # how we link (symlink default) 
  29. $def_port=70;                     # default port
  30. $using_dir_list=0;                # set this if using list of directories
  31. $dirfilename="./gopherdirs";      # file with list of directories (see getdirs)
  32. $names='.names';                  # default .link file 
  33.  
  34. if($using_dir_list){
  35. require ("win.pl");               # and an ansi knowledgable term
  36. }
  37. # End configure
  38. #
  39. # get some user stuff
  40. (defined $ENV{'EDITOR'}) && ($ed = $ENV{'EDITOR'});
  41. (defined $ENV{'PAGER'})&&($pager = $ENV{'PAGER'});
  42.  
  43. system("clear");
  44. @stack='';
  45. $dir='.';
  46. print "Welcome GopherMeister...\n";
  47. if($using_dir_list){
  48.   open(DIRS,"<$dirfilename")||die "cant open";
  49.   while(<DIRS>){
  50.     chop;$dirs{$_}=1;
  51.   }
  52.   close(DIRS);
  53.   print "Select starting directory? (y|n) > ";
  54.   $ans=<STDIN>;
  55.   $ans=~/^[Yy]/ && ($firstdir=1);
  56.   if($firstdir){
  57.     $firstdir=&select_dir;
  58.     $firstdir=~s/^\/(.*)\/?$/$1/;
  59.     @stack=split('/',$firstdir);
  60.   }
  61. }
  62.  
  63. while($dir ne 'last'){
  64.   %files=%links=%caps=%cache=%all=();
  65.   ($dir eq "..") ? pop(@stack):(($dir ne '.') && push(@stack,$dir));
  66.   $realdir=$toplevel.join('/',@stack);
  67.   $realdir=~s#(/)/#$1#;
  68.   if(!(-d "$realdir")){
  69.     print "Bad directory selection, returning to toplevel\n";
  70.     $realdir=$toplevel;
  71.     @stack=("");
  72.   }
  73.   chdir $realdir || die "real trouble\n";
  74.   $dir=&read_em;
  75. }
  76.  
  77.    
  78. sub bygroup{
  79. local($namea,$typea,$patha,$hosta,$porta,$numba,$statusa)=split('#,#',$all{$a});
  80. local($nameb,$typeb,$pathb,$hostb,$portb,$numbb,$statusb)=split('#,#',$all{$b});
  81.   if($numba < $numbb){
  82.     return -1;
  83.   }elsif($numba > $numbb){
  84.     return 1;
  85.   }else{
  86.     if($namea lt $nameb){
  87.       return -1;
  88.     }elsif($namea gt $nameb){
  89.       return 1;
  90.     }else{
  91.         return 0;
  92.     }
  93.   }
  94. }
  95.  
  96. sub read_em{
  97.   local($i,$j);
  98.   local($name,$type,$path,$host,$port,$numb,$status);
  99.   local(@parse);
  100.   (-d ".cap") && (%caps = &read_caps); 
  101.   %links = &read_links;
  102.   %files = &read_files;
  103.   for (keys(%files)){ 
  104.     ($name,$type,$path,$host,$port,$numb,$status)=&parsef($_);
  105.      $path=~s/.*\///;
  106.     if(defined($caps{$_})){
  107.       @parse=&parse($caps{$_},$name,$type,$path,$host,$port,$numb,$status); 
  108.       $all{$_}=join('#,#',@parse);
  109.     }elsif(defined($links{$_})){
  110.       @parse=&parse($links{$_},$name,$type,$path,$host,$port,$numb,$status); 
  111.       $all{$_}=join('#,#',@parse);
  112.     }else{
  113.       $all{$_}=join('#,#',($name,$type,$path,$host,$port,$numb,$status));
  114.     }
  115.   } 
  116.   for (keys(%links)){
  117.     next if (defined($all{$_}));
  118.     $type=$path=$host='undefined';
  119.     $name=$_;
  120.     $status="OK";
  121.     @parse=&parse($links{$_},$name,$type,$path,$host,$port,$numb,$status); 
  122.     $all{$_}=join('#,#',@parse);
  123.   } 
  124.   for (keys(%caps)){ 
  125.     next if (defined($all{$_}));
  126.     $type=$path=$host='undefined';
  127.     $name=$_;
  128.     $status="OK";
  129.     @parse=&parse($caps{$_},$name,$type,$path,$host,$port,$numb,$status); 
  130.     $all{$_}=join('#,#',@parse);
  131.   } 
  132.   @keys=sort bygroup keys(%all);
  133.   system "clear";
  134.   for(;;){
  135.     if($i>$plen){
  136.       $l = length($realdir);
  137.       ($l>60) ? ($c_dir=substr($realdir,$l-60)):($c_dir=$realdir);
  138.       print "\ncwd: $c_dir (h for help) > ";
  139.       chop($num=<STDIN>); 
  140.       if($num =~ /^[Ff]/){
  141.        $j += ($plen+1) unless ($j>=$#keys); 
  142.       }elsif($num =~ /^[Bb]/){
  143.        $j -= ($plen+1) unless ($j<=($plen+1)); 
  144.       }elsif($num =~ /^\!(.*)/){
  145.         system("$1");
  146.         print " Carriage Return to continue > ";
  147.         chop($num=<STDIN>); 
  148.         $dir = '.';
  149.         last;
  150.       }elsif($num =~ /^[Cc]/){
  151.         print "Enter number of directory to change to ";
  152.         if($using_dir_list){
  153.           print ", or a ? to use directory selector > ";
  154.           chop($c=<STDIN>); 
  155.         }else{
  156.           print "> ";
  157.           chop($c=<STDIN>); 
  158.         }
  159.         if($using_dir_list){
  160.           if($c =~ /^\s*[?]/){
  161.             ($c=&select_dir) && ($c=~s/^\/(.*)\/?$/$1/);
  162.             @stack=split('/',$c);
  163.             $dir='.';
  164.           }else{
  165.             defined($keys[$c]) ? ($dir=$keys[$c]) : ($dir = '.');
  166.           } 
  167.         }else{
  168.           defined($keys[$c]) ? ($dir=$keys[$c]) : ($dir = '.');
  169.         }
  170.         last;
  171.       }elsif($num =~ /^[Hh]/){
  172.         &give_a_clue1;
  173.       }elsif($num =~ /^[Dd]/){
  174.         &create_dot_names;
  175.         $dir='.';
  176.         last;
  177.       }elsif($num =~ /[Qq]/){
  178.         $dir='last';
  179.         last;
  180.       }elsif(($num =~/^\d/) && ($num <= $#keys)){
  181.         $num = &view_lead($keys[$num]);
  182.         $dir='.';
  183.         last if $num == -1; 
  184.       }
  185.       $j-=($plen+1); 
  186.       system "clear";
  187.       $- = 0;
  188.       $i=0; next;
  189.     }else{
  190.       $t="$j>";
  191.       ($j==0 )&&($t='0>'); 
  192.       if($j > $#keys) {$t=undef;@a=("");}
  193.       else{@a = split('#,#',$all{$keys[$j]});}
  194.       write;
  195.       $i++;$j++;
  196.     }
  197.   }
  198. $- = 0;
  199. $dir;
  200. }    
  201.  
  202. format STDOUT =
  203. @<<< @<<<<<<<<<<<<<<<<<<<< @| @||||||||||||||| @<<<<<<<<<<<<<< @>>> @||| @>>>>>
  204. $t,$a[0],$a[1],$a[2],$a[3],$a[4],$a[5],$a[6]
  205. .
  206.  
  207. format STDOUT_TOP =
  208. Num        Name           Type    Path             Host        Port Numb Status
  209. -------------------------------------------------------------------------------
  210. .
  211.  
  212. sub read_caps{
  213. local(%tmp,@files);
  214. #  read the .caps files corresponding to the current dir
  215. opendir(CURDIR,".cap");
  216. @files = grep(!/^\.\.?$/, readdir(CURDIR));
  217. $/="";
  218. for (@files){
  219.   @stat=stat(".cap/$_");
  220.   if((-T _)&&(-r _)&&(-e $_)){
  221.     if(!((($stat[2] >> 6) & 04)&&(($stat[2] >> 3) & 04)&&($stat[2] & 04))){
  222.       $tmp{$_}.=".cap/$_ : not world readable\n";
  223.     }else{
  224.       $tmp{$_}.=".cap/$_: world readable\n";
  225.     }
  226.     open(CAP,"<.cap/$_");
  227.     $entry =<CAP>;
  228.     close CAP; 
  229.     $tmp{$_} .= "$entry";
  230.   }else{
  231.     $tmp{".cap/$_"} .= "ERROR in .cap/$_,\n not a regular text file, or not readable,\nor corresponding $_ does not exist\n";
  232.   }
  233. }
  234. $/="\n";
  235. %tmp;
  236. }
  237.  
  238. sub read_links{
  239. local(%tmp,@files,$i);
  240. local($name,$type,$path,$host,$status);
  241. #  read the .caps files corresponding to the $dir
  242. opendir(CURDIR,".");
  243. #@files = grep(/^\..*[LlNn][IiAa][NnMm][KkEe][Ss]?$/, readdir(CURDIR));
  244. @files = grep(/^\.\w.*$/, readdir(CURDIR));
  245. $/="";
  246. $i=1;
  247. for $f (@files){
  248.   next if ($f eq ".cache");
  249.   next if (-d "./$f");
  250.   if((-T $f)&&(-r $f)){
  251.     open(LINK,"<$f");
  252.     while(<LINK>){
  253.       ($name,$type,$path,$host,$port,$numb,$status)=&parse($_); 
  254.       $tmp{$path} ="$f\n$_";
  255.     }
  256.     close(LINK);
  257.   }else{
  258.     $tmp{$f} = "Not a regular .link or .names file,\n or not readable.";
  259.   }
  260. }
  261. $/="\n";
  262. %tmp;
  263. }
  264.  
  265. sub read_files{
  266.   local (%tmp);
  267.   local($i);
  268.   local(@files);
  269.   opendir(CURDIR,".");
  270.   @files = grep(!/^\.$/, readdir(CURDIR));
  271.   closedir CURDIR;  
  272.   for (@files){
  273.     $tmp{$_}=join('/',grep(/[\S]/,@stack))."/$_";
  274.     @stat=stat($_);
  275.     $r = ((($stat[2] >> 6) & 04)&&(($stat[2] >> 3) & 04)&&($stat[2] & 04));
  276.     $x = ((($stat[2] >> 6) & 01)&&(($stat[2] >> 3) & 01)&&($stat[2] & 01));
  277.     if(-d _){
  278.       $tmp{$_}.=" : Dir";
  279.       (!$x) && ($tmp{$_}.= ": NOT world scannable");
  280.       $tmp{$_}.="\n";
  281.     }
  282.     if(-f _){
  283.       (-T _) ? ($tmp{$_}.=" : Text\n"):($tmp{$_}.=" : NoTxt\n");
  284.     }
  285.     if(!(-r _)){
  286.       $tmp{$_}.="ERROR not readable:";
  287.     }elsif(!$r){
  288.       $tmp{$_}.="Not world readable :";
  289.     }else{
  290.       $tmp{$_}.="World readable :";
  291.     }
  292.     if(-l "$_"){
  293.       $realname=readlink($_);
  294.       $tmp{$_}.=" symlink to $realname\n"; 
  295.     }elsif((-f _)||(-d _)){
  296.       $tmp{$_}.=" regular file or dir\n"; 
  297.     }else{
  298.       $tmp{$_}.=" not regular file or dir\n"; 
  299.     } 
  300.     $tmp{$_}.="Owner:  ".getpwuid($stat[4])." Group:  ".getgrgid($stat[5])."\n";
  301.     $tmp{$_}.="atime: ".&ctime($stat[8]);
  302.     $tmp{$_}.="ctime: ".&ctime($stat[10]);
  303.   }
  304. %tmp
  305. }
  306.  
  307. sub give_a_clue1{
  308. local ($ans);
  309. system ("clear");
  310. print <<"HelpEnd";
  311.                Gopher Environment Editor - Main Menu Help
  312.  
  313. All commands must be followed by a carriage return
  314. At the main menu of items you can enter the following commands:
  315.  
  316. [number]   view item stat info and .cap/.link/.name info, if any
  317. c          change to directory [number]
  318. h          This help section
  319. f          forward page or same page at end
  320. b          back a page or same page at beginning
  321. q          quit
  322. !command   execute command in current dir
  323.  
  324. HelpEnd
  325. print "\n<CR> to continue >";
  326. $ans=<STDIN>;
  327. }
  328.  
  329. sub view_lead{
  330. local($key) = @_;
  331. local(@text)=();
  332. system ("clear");
  333. defined($files{$key}) ? (@finfo=split(/\n/,$files{$key})):(@finfo=("None"));
  334. defined($caps{$key}) ? (@cinfo=split(/\n/,$caps{$key})):(@cinfo=("None"));
  335. defined($links{$key}) ? (@linfo=split(/\n/,$links{$key})):(@linfo=("None"));
  336. @lines=("Stat info: ",@finfo,'', ".cap file info:",@cinfo,'',".link or .name file info:",@linfo);
  337. local($i,$tmp);
  338. $header=substr($key,0,30);
  339. print "Displayed Info: $header\n\n";
  340. for (@lines){
  341.   print "$_\n";
  342. }
  343. print "\nEnter selection key, or h for help, or <CR> to return to main menu > ";
  344. $ans=<STDIN>;
  345. &do_sumthin($ans,$key);
  346. $ans=~/^[EeDdMm]/ && (return -1);
  347. }
  348.  
  349. sub do_sumthin{
  350. local($ans,$key)=@_;
  351.   if($ans =~ /^[Dd]/){
  352.   &delete_file($key);
  353.  }elsif($ans =~ /^[Ee]/){
  354.   &change_display($key);
  355.  }elsif($ans =~ /^[Hh]/){
  356.   &give_a_clue2;
  357.  }elsif($ans =~ /^[Mm]/){
  358.   &mv_file($key);
  359.  }elsif($ans =~ /^[Vv]/){
  360.   &view_file($key);
  361.  }
  362. }
  363.  
  364. sub view_file{
  365. local ($key)=@_;
  366. system("$pager $key");
  367. }
  368.  
  369. sub mv_file{
  370. local ($key)=@_;
  371. local($d,$newdir);
  372. system ("clear");
  373. print "\n\nThe following selections are available:\n\n";
  374. print "1> $mv $key to another directory\n";
  375. print "2> $cp $key to another directory\n";
  376. print "3> $ln $key to another directory\n";
  377. print "4> Forget about this altogther.\n\n";
  378. print "Select the number of your choice > ";
  379. chop($ans=<STDIN>);
  380. (($ans>3)||($ans <1)) && (print "aborting\n") && (return);
  381. ($ans==1) && ($com = $mv);
  382. ($ans==2) && ($com = $cp);
  383. ($ans==3) && ($com = $ln);
  384.  
  385. if(-T $key){
  386.   print "View file $key now? (y|n) > ";
  387.   chop($tmp=<STDIN>);
  388.   ($tmp=~/^[Yy]/) && &view_file($key);
  389. }
  390. print "Enter new dir for $key from toplevel";
  391. ($using_dir_list) ? (print ", ? to use selector\n > "):(print "\n > ");
  392. chop($d=<STDIN>); 
  393.  
  394. if($using_dir_list){
  395.   ($d =~ /^\s*[?]/) && ($d=&select_dir) && ($d=~s/^\/?(.*)\/?$/$1/);
  396.   $newdir=$toplevel.$d;
  397.   system ("clear");
  398.   print "\n$com $key to $newdir/$key ? (y|n) > ";
  399.   $ans=<STDIN>;
  400.   ($ans=~/^[Nn]/) && return;
  401.   if(-d $newdir){
  402.     system("$com $key $newdir/$key");
  403.   }else{ print "Dir $d does not exist\n"; }
  404. }else{
  405.   $newdir=$toplevel.$d;
  406.   system ("clear");
  407.   print "\n$com $key to $newdir/$key ? (y|n) > ";
  408.   $ans=<STDIN>;
  409.   ($ans=~/^[Nn]/) && return;
  410.   if(-d $newdir){
  411.     system("$com $key $newdir/$key");
  412.   }else{ print "Dir $d does not exist"; }
  413. }
  414.   
  415. }
  416.  
  417. sub delete_file{
  418. local ($key)=@_;
  419. system("clear");
  420. local($summary,$done);
  421. print "Are you sure you want to delete this file? (Y|N) >";
  422. $summary=<STDIN>;
  423. if($summary=~/^[Yy]/){
  424.   system("$rm $key");
  425.   $! && do (print "not deleted\n" && return);
  426.   print "deleted...\n" ;
  427.   return;
  428. }
  429. print "not deleted...\n";
  430. sleep 1;
  431. }
  432.  
  433. sub give_a_clue2{
  434. local ($ans);
  435. system ("clear");
  436. print <<"HelpEnd";
  437.                Gopher Environment Editor - File Info Help
  438.  
  439. All commands must be followed by a carriage return
  440. While viewing info on an item you can enter the following commands:
  441.  
  442. d   delete this file from the archive
  443. e   change/create displayed info for this item
  444. h   This help section
  445. v   view this file
  446. m   mv, cp, or ln this file somewhere else [use dir list]
  447.  
  448. HelpEnd
  449. print "\n<CR> to continue >";
  450. $ans=<STDIN>;
  451. }
  452.  
  453. sub change_display{
  454. local($f)=@_;
  455. local($name,$type,$path,$host,$port,$numb,$status);
  456. if(-T $f){
  457.   print "View file $f now? (y|n) > ";
  458.   chop($tmp=<STDIN>);
  459.   ($tmp=~/^[Yy]/) && &view_file($f);
  460. }
  461. if(defined($links{$f})){
  462.   ($file)=split('\n',$links{$f});
  463.   print "Edit the link $f in $file now? (y|n) > ";
  464.   $ans=<STDIN>;
  465.   $ans =~ /[Nn]/ && return;
  466.   system("$ed $file");
  467.   print "Did you make changes? (y|n) > ";
  468.   $ans=<STDIN>;
  469.   $ans =~ /[Nn]/ && return;
  470.   &nuke_cache || die "cant nuke the .cache file\n";
  471.   return;
  472. }else{
  473.   ($name,$type,$path,$host,$port,$numb,$status)=&parsef($f); 
  474.   $type=&get_type($type);
  475.   if(defined($caps{$f})){
  476.     ($name,$type,$path,$host,$port,$numb,$status)=
  477.      &parse($caps{$f},$name,$type,$path,$host,$port,$numb,$status);
  478.     print "File already has a .cap entry, overwrite? (y|n) > ";
  479.     chop($ans=<STDIN>);
  480.     if($ans =~ /^[Nn]/){
  481.       print "Edit the .cap file for $f? (y|n) > ";
  482.       chop($ans=<STDIN>);
  483.       $ans =~ /^[Nn]/ && return;
  484.       system("$ed" , ".cap\/$f");
  485.       print "Did you make changes? (y|n) > ";
  486.       $ans=<STDIN>;
  487.       $ans =~ /[Nn]/ && return;
  488.       &nuke_cache || die "cant nuke the .cache file\n";
  489.       return;
  490.     }
  491.   }
  492.   $ans="n";
  493.   while($ans !~ /^[Yy]/){
  494.     print "Enter Displayed name for item: [$name] \n> ";
  495.     chop($tmp=<STDIN>);
  496.     (length($tmp) > 0) && ($name=$tmp);
  497.     if(defined($numb)){
  498.       print "Enter Numb for file: [$numb]\n> ";
  499.       chop($tmp=<STDIN>);
  500.       (length($tmp) > 0) && ($numb=$tmp);
  501.     }
  502.     print "Enter Type for file: [$type]\n> ";
  503.     chop($tmp=<STDIN>);
  504.     (length($tmp) > 0) && ($type=$tmp);
  505.     print "Enter Host for file: [$host]\n> ";
  506.     chop($tmp=<STDIN>);
  507.     (length($tmp) > 0) && ($host=$tmp);
  508.     print "Enter Port for file: [$port]\n> ";
  509.     chop($tmp=<STDIN>);
  510.     (length($tmp) > 0) && ($port=$tmp);
  511.     print "Use a \"Path=\" entry for this item? (y|n) > ";
  512.     $tmp=<STDIN>;
  513.     if($tmp=~/^[Yy]/){
  514.       print "Enter Path for file: [$type/$path]\n> ";
  515.       chop($p=<STDIN>);
  516.       (length($p) > 0) && ($path=$p);
  517.       $path=~s/\s*$//;
  518.     }
  519.     $entry="Name=$name\n";
  520.     if(defined($numb)){
  521.       $entry.="Numb=$numb\n";
  522.     }
  523.     $entry.="Type=$type\n";
  524.     if($tmp=~/^[Yy]/){
  525.       $entry.="Path=$type/$path\n";
  526.     }
  527.     $entry.="Host=$host\nPort=$port\n";
  528.     print "\n$entry\n\n"."This look ok? (y|n) > "; 
  529.     $ans=<STDIN>;
  530.   }
  531.   system ("clear");
  532.   print $entry."\n\n\n";
  533.   print "1> Create this .cap file\n";
  534.   print "2> Append this entry to $names file\n";
  535.   print "3> Forget this entry\n";
  536.   print "Select the number of your choice > ";
  537.   chop($ans=<STDIN>);
  538.   if($ans==1){
  539.     &nuke_cache || die "cant nuke the .cache file\n";
  540.     (-d ".cap") || mkdir(".cap",0755) || die "cant create .cap dir\n";
  541.     open(CAP,">.cap/$f")||die "cant open the .cap file";
  542.     print CAP $entry;
  543.     close CAP;
  544.   }elsif($ans==2){
  545.     &nuke_cache || die "cant nuke the .cache file\n";
  546.     open(NAMES,">>$names")||die "cant open $names\n";
  547.     print NAMES "\n$entry\n";
  548.     close NAMES;
  549.   }
  550. }    
  551. }
  552.  
  553.  
  554. sub parsef{
  555. local($name)=@_;
  556. local(@l,$type,$path,$host,$port,$numb,$status);
  557. $status='OK'; 
  558. $numb=undef;
  559. $port=$def_port;
  560. @l=split('\n',$files{$name});
  561. ($path,$type) = split(':',$l[0]);
  562. $path=~s/\s*$//;
  563. $host=$thishost;
  564. $files{$name} =~ /(ERROR)/ && ($status=$1);
  565. ($name,$type,$path,$host,$port,$numb,$status);
  566. }
  567.  
  568.  
  569. sub parse{
  570. local($entry,$name,$type,$path,$host,$port,$numb,$status)=@_;
  571. local($gotit);
  572. $entry =~ /Name=(.*)\s*\n{1,1}/ && ($name=$1);
  573. $entry =~ /Type=(.*)\s*\n{1,1}/ && ($type=$1);
  574. $entry =~ /Path=([\dm])?(.*)\s*\n{1,1}/ && ($type=$1,$path=$2,$gotit=1);
  575. $entry =~ /Host=(.*)\s*\n{1,1}/ && ($host=$1);
  576. $entry =~ /Port=(.*)\s*\n{1,1}/ && ($port=$1);
  577. $entry =~ /Numb=(.*)\s*\n{1,1}/ && ($numb=$1);
  578. if(($host eq "undefined")||($host eq "+")||($host eq "$thishost")){
  579.   $tmp =  $toplevel.$path;
  580.   (-e $tmp) && $gotit && ($path=~s/.*\/(.*)/$1/);
  581. }
  582. $entry =~ /(ERROR)/ && ($status=$1);
  583. ($name,$type,$path,$host,$port,$numb,$status);
  584. }
  585.  
  586. sub nuke_cache{
  587.  (-f ".cache") && (unlink(".cache") || return 0);
  588.  return 1;
  589. }
  590. sub do_new_cache{
  591.  (-f ".cache") && unlink(".cache") || die "you cant do that";
  592. }
  593. sub get_type{
  594.  local($type)=@_;
  595.  local($tmp)=$type;
  596.  ($type =~ /^\s*D/) && ($tmp=1);
  597.  ($type =~ /^\s*T/) && ($tmp=0);
  598. $tmp;
  599. }
  600.  
  601. sub select_dir{
  602.  system("clear");
  603.  local(@b)=();
  604.  local(@text)=();
  605.  local($key);
  606.  $title='Select preferred directory';
  607.  $footer='b = back a page, /[keyword] = search';
  608.  local($i,$j);
  609.  local(@win)=(1,22,79,1,0,7,$title,$footer);
  610.  &win'title(@win);
  611.  &win'footer(@win);
  612. @b= sort (keys(%dirs));
  613. for ($i=0,$j=0;$i <= $#b;$i++,$j++){
  614.  if($j==$plen){     # buffer full, refresh screen
  615.     &win'refresh(scalar(@text),@text,scalar(@win),@win);
  616.     $tmp=&win'getdata(1,23,"select dir number or <CR> for more >",7);
  617.     ($tmp =~ /^\d/) && (defined($b[$tmp])) && (return($b[$tmp]));
  618.     if(($tmp =~ /^\/(.*)\n?$/) && ($key = $1)){
  619.       $tmp2=$i;
  620.       for(;$i <= $#b;$i++){
  621.         last if ($b[$i] =~ /$key/);
  622.         if($i>=$#b){
  623.           &win'getdata(1,23,"Not Found, <CR> to continue >",7);
  624.           $i=$tmp2;
  625.           last;
  626.         }
  627.       }
  628.     }elsif($tmp =~ /^[Bb]/){
  629.       $i -= (2*$plen);
  630.     }
  631.     $j=0;
  632.     $text[$j] = "$i> $b[$i]";
  633.  }else{
  634.     $text[$j] = "$i> $b[$i]";
  635.  }
  636. }
  637. @text[$j..$plen]=();
  638. &win'refresh(scalar(@text),@text,scalar(@win1),@win1);
  639. $tmp=&win'getdata(1,23,"select dir number or <CR> to return >",7);
  640. ($tmp =~ /^\d/) && (defined($b[$tmp])) && (return($b[$tmp]));
  641. return ('.');
  642. }
  643.